<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">

    function fun() {

        //创建对象
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        //向服务器发送请求,true是异步，false是同步
        xmlhttp.open("GET", "ajaxServlet?username=tom", true)

        //如果是get请求，send发送空的，如果是post请求，seng就带参数
        xmlhttp.send();

        //

    }
</script>


<button type="button" id="btn1" onclick="fun()">发送请求</button>
</body>
</html>